package com.spa.interfaces.shop;

import com.spa.application.command.shop.ShopWithdrawApplyNewCommand;
import com.spa.application.command.shop.WithdrawAuditCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.massagist.OrderListWithdrawDTO;
import com.spa.application.dto.massagist.WithdrawAccountDTO;
import com.spa.application.dto.shop.*;
import com.spa.application.query.shop.*;
import com.spa.application.service.shop.ShopWithdrawApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.interfaces.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@RestController
@RequestMapping("shop/withdraw")
public class ShopWithdrawController extends BaseController {

    @Autowired
    private ShopWithdrawApplicationService shopWithdrawApplicationService;

    @PostMapping("finance")
    public ResponseMessage<ShopFinanceDTO> finance() {
        return responseHelper.success(shopWithdrawApplicationService.finance());
    }

    @PostMapping("audit/page")
    public ResponseMessage<PageResult<ShopWithdrawAuditListDTO>> auditPage(@Validated @RequestBody ShopWithdrawAuditQuery query) {
        return responseHelper.success(shopWithdrawApplicationService.auditPage(query));
    }

    @PostMapping("order/list")
    public ResponseMessage<PageResult<OrderListWithdrawDTO>> withdrawOrderList(@Validated @RequestBody ShopWithdrawRecordDetailQuery query) {
        return responseHelper.success(shopWithdrawApplicationService.massagistWithdrawOrderList(query));
    }

    @PostMapping("progress")
    public ResponseMessage<ShopWithdrawProgressDTO> progress(@Validated({ShopWithdrawQuery.QueryById.class}) @RequestBody ShopWithdrawQuery query) {
        return responseHelper.success(shopWithdrawApplicationService.progress(query));
    }

    @PostMapping("audit")
    public ResponseMessage audit(@Validated @RequestBody WithdrawAuditCommand command) {
        shopWithdrawApplicationService.audit(command);
        return responseHelper.success();
    }

    @PostMapping("v2/apply")
    public ResponseMessage applyNew(@Validated @RequestBody ShopWithdrawApplyNewCommand command) {
        shopWithdrawApplicationService.applyNew(command);
        return responseHelper.success();
    }

    @PostMapping("page")
    public ResponseMessage<PageResult<ShopWithdrawListDTO>> page(@Validated({ShopWithdrawQuery.QueryList.class}) @RequestBody ShopWithdrawQuery query) throws ParseException {
        return responseHelper.success(shopWithdrawApplicationService.page(query));
    }

    @PostMapping("withdrawOrderList")
    public ResponseMessage<PageResult<ShopWithdrawOrderListDTO>> withdrawOrderList(@RequestBody ShopWithdrawOrderListQuery query) {
        return responseHelper.success(shopWithdrawApplicationService.orderList(query));
    }

    @PostMapping("orderDetail")
    public ResponseMessage<ShopWithdrawOrderDetailDTO> orderDetail(@Validated @RequestBody ShopWithdrawOrderDetailQuery query) {
        return responseHelper.success(shopWithdrawApplicationService.orderDetail(query));
    }

    @PostMapping("withdrawRecordDetailOrderList")
    public ResponseMessage<PageResult<ShopWithdrawOrderListDTO>> withdrawRecordDetailOrderList(@Validated @RequestBody ShopWithdrawRecordDetailOrderListQuery query) {
        return responseHelper.success(shopWithdrawApplicationService.withdrawOrderList(query));
    }

    @PostMapping("orderTotal")
    public ResponseMessage<Integer> orderTotal() {
        return responseHelper.success(shopWithdrawApplicationService.withdrawOrderTotal());
    }

    @PostMapping("lastWithdrawAccount")
    public ResponseMessage<WithdrawAccountDTO> lastWithdrawAccount() {
        return responseHelper.success(shopWithdrawApplicationService.lastWithdrawAccount());
    }

}
